//
//  ST_ExampleTraitCell.swift
//  btvideo
//
//  Created by Jason on 2021/9/26.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift


class ST_ExampleTraitCell: UICollectionViewCell {
    
    static let locPecGap = 5.cgFloat
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.contentView.backgroundColor = Color.white
        
//        self.contentView.backgroundColor = Color.random
        
        contentView.addSubview(cover_image_view)
        
        contentView.addSubview(icon_image_view)
        contentView.addSubview(content_label)
        contentView.addSubview(left_icon_image_view)
        contentView.addSubview(peculiarity_label)
        
        
        cover_image_view.snp.makeConstraints { (make) in
            make.top.right.left.equalToSuperview()
            make.height.equalTo(50)
        }
        
        content_label.snp.makeConstraints { (make) in
            make.top.equalTo(cover_image_view.snp.bottom).offset(10)
            make.left.equalTo(cover_image_view).offset(13)
            make.width.equalTo(40)
            make.height.equalTo(14)
        }
        
        
        
        left_icon_image_view.snp.makeConstraints { (make) in
            make.centerY.equalTo(content_label)
            make.left.equalToSuperview().offset(5)
            make.width.equalTo(4)
            make.height.equalTo(6)
        }
        
        peculiarity_label.snp.makeConstraints { (make) in
            make.left.equalTo(content_label.snp.right).offset(ST_ExampleTraitCell.locPecGap)
            make.centerY.equalTo(content_label)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    fileprivate lazy var pauseSignImageView:UIImageView = {
//        let control = UIImageView.init(image: ST_ImageUtils.imageName("pause"))
//        control.isHidden = true
//        return control
//    }()
    
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 20
        return control
    }()
    
    fileprivate lazy var icon_image_view:ST_TriangleView = {
        let control = ST_TriangleView()
        return control
    }()
    
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.textColor = UIColor.init(hex: 0x333333)
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var peculiarity_label:UILabel = {
        let control = UILabel.init()
        control.textColor = UIColor.init(hex: 0xFEC207)
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
  
    fileprivate lazy var left_icon_image_view:ST_TriangleView = {
        let control = ST_TriangleView()
        return control
    }()
    
//    MARK: - Bind Model
    var model = ST_ExampleTraitCellModel(){
        didSet{
            
            cover_image_view.pin_setImage(from: model.content.compress_small_image(width: 800).url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
//        cover_image_view.pin_setImage(from: model.content.compress_small_image(width: ScreenWidth-35).url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        
        cover_image_view.snp.updateConstraints { (make) in
            make.height.equalTo(model.imgDisplayHeight)
        }
        
        content_label.snp.updateConstraints { (make) in
            make.width.equalTo(model.contentWidth)
        }
            
        content_label.text = model.display_text
        
        peculiarity_label.text = model.feature_name
            
        }
    }
}
